$(document).ready(function(){
    $("#articlesubmit").bind("click",function(){
        //ajax post
        var options = {
            success:function(data){
                var dataObj=eval("("+data+")");
                if(dataObj.code===0){
                    window.location.href="adminarticle/";
                }else{
                    $("#error").text(data);
                }
            }
        }
        $("#articleform").ajaxSubmit(options);
    });
    
    $("#articleupdate").bind("click",function(){
        //ajax post
        var options = {
            success:function(data){
                var dataObj=eval("("+data+")");
                if(dataObj.code===0){
                    window.location.href="adminarticle/";
                }else{
                    $("#error").text(data);
                }
            }
        }
        $("#articleupdateform").ajaxSubmit(options);
    });

    $("#articledelete").bind("click",function(){
        //ajax post
        var options = {
            success:function(data){
                var dataObj=eval("("+data+")");
                if(dataObj.code===0){
                    window.location.href="adminarticle/";
                }else{
                    $("#error").text(data);
                }
            }
        }
        $("#articledeleteform").ajaxSubmit(options);
    });


   $("#cancel").bind("click", function(){
        $("#error").text("");   
    })
})

function update(articlename){
    var name = "tr[id='"+ articlename+"']"  + "\t"+ "td:eq(1)";
    var description = "tr[id='"+ articlename+"']"  + "\t"+ "td:eq(2)";
    var name_text = $(name).text();
    var description_text = $(description).text();
    $("#nameupdate").attr("value", name_text);
    $("#nameupdateold").attr("value", name_text);
    $("#descriptionupdate").attr("value", description_text);
}
function deletes(articlename){
    var name = "tr[id='"+ articlename+"']"  + "\t"+ "td:eq(1)";
    var description = "tr[id='"+ articlename+"']"  + "\t"+ "td:eq(2)";
    var name_text = $(name).text();
    var description_text = $(description).text();
    $("#namedelete").attr("value", name_text);
    $("#namedeletedisable").attr("value", name_text);
    $("#descriptiondelete").attr("value", name_text);
    $("#descriptiondeletedis").attr("value", description_text);
}

